import 'package:flutter/material.dart';

class Test006 extends StatefulWidget {
  const Test006({Key? key}) : super(key: key);

  @override
  State<Test006> createState() => _Test006State();
}

class _Test006State extends State<Test006> with TickerProviderStateMixin {
  late AnimationController _controller;
  late AnimationController _opacityController;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
    _opacityController = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("动画"),
      ),
      body: Center(
        child:FadeTransition (
          opacity: Tween(begin: 1.0,end: 0.5).animate(_opacityController),
          child: AnimatedBuilder(
            animation: _controller,
            builder: (BuildContext context, Widget? child) {
              return Container(
                width: 300,
                height: 300,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: Colors.blue,
                  gradient: RadialGradient(
                    colors: [
                      Colors.blue.shade600,
                      Colors.blue.shade100,
                    ],
                    stops: [_controller.value, _controller.value + 0.1],
                  ),
                ),
              );
            },
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async{
          // 4 7 8
          _controller.duration = const Duration(seconds: 4);
          _controller.forward();

          await Future.delayed(const Duration(seconds: 4));

          _opacityController.duration  = const Duration(seconds: 2);
          _opacityController.repeat(reverse: true);

          await Future.delayed(const Duration(seconds: 8));
          _opacityController.reset();


          _controller.duration = const Duration(seconds: 7);
          _controller.reverse();

        },
        child: const Icon(Icons.ads_click),
      ),
    );
  }
}
